package com.mentaleye.service.impl;

import com.mentaleye.bean.CurriculumBean;
import com.mentaleye.dal.dao.CurriculumDao;
import com.mentaleye.dal.model.Curriculum;
import com.mentaleye.dal.model.CurriculumExample;
import com.mentaleye.enums.CommonStatus;
import com.mentaleye.service.CurriculumService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class CurriculumServiceImpl implements CurriculumService {
     @Autowired
	 private CurriculumDao curriculumDao;

	@Override
	public CurriculumBean getCurriculumByNo(Integer no) {
		return (CurriculumBean)ObjectUtil.transfer(curriculumDao.getCurriculumByNo(no),CurriculumBean.class);
	}

	public boolean editCurriculum(CurriculumBean curriculumBean, boolean add) {
		boolean result=false;
		Curriculum curriculum= (Curriculum)ObjectUtil.transfer(curriculumBean,Curriculum.class);
		if(add){
			curriculum.setCurriculumStatus(CommonStatus.DEFAULT.getCode());
			result=curriculumDao.addCurriculum(curriculum);
		}else{
			result=curriculumDao.editCurriculum(curriculum);
		}
		return  result;
	}
	@SuppressWarnings("unchecked")
	public List<CurriculumBean> queryCurriculum(String curriculumName, List<String> cotainNos, List<String> unCotainNos,
												String readyRelate, String noRelate) {
		return  ObjectUtil.transferListMap(curriculumDao.queryCurriculum(curriculumName,  cotainNos,   unCotainNos,
				  readyRelate,   noRelate), CurriculumBean.class);
	}
	public List<CurriculumBean> queryCurriculum(CurriculumExample example) {
		return ObjectUtil.transferList(curriculumDao.queryCurriculum(example),CurriculumBean.class);
	}
	
	@SuppressWarnings("unchecked")
	public List<CurriculumBean> queryCurriculumByPage(Map<String, Object> map) {
	   return (List<CurriculumBean>) ObjectUtil.transferListMap(curriculumDao.queryCurriculum(map), CurriculumBean.class);
	}



	public boolean deleteCurriculum(List<Integer> ids) {
		return curriculumDao.deleteCurriculum(ids);
	}
	@SuppressWarnings("unchecked")
	public List<CurriculumBean> queryCurriculum(Map<String, Object> map) {
		return (List<CurriculumBean>) ObjectUtil.transferListMap(curriculumDao.queryCurriculum(map),CurriculumBean.class);
	}

}